﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using MvcEngine.Core;
using MvcEngine.Core.Services;
using MvcEngine.Mvc.Extensions;
using MvcEngine.Mvc.Constraints;
using MvcEngine.Core.Content;
using MvcEngine.Core.HttpHandlers;

namespace MvcEngine.Mvc.Areas.StarterSite
{
    public class CommonRoutes : AreaRegistration
    {
        public override void RegisterArea(AreaRegistrationContext context)
        {
            IgnoreRoutes(context);

            context.MapMvcEngineRoute(
                 "Common_ModuleCssFile",
                 "Modules/{moduleName}/areas/{area}/content/{fileName}"
            );
        }

        public override string AreaName
        {
            get { return "StarterSite"; }
        }

        protected virtual void IgnoreRoutes(AreaRegistrationContext context)
        {
            context.Routes.RouteExistingFiles = true;

            // Ignore text, html, xml files.
            context.Routes.IgnoreRoute("{file}.txt");
            context.Routes.IgnoreRoute("{file}.htm");
            context.Routes.IgnoreRoute("{file}.html");
            context.Routes.IgnoreRoute("{file}.xml");
            context.Routes.IgnoreRoute("{file}.js");
            context.Routes.IgnoreRoute("{file}.jpg");
            context.Routes.IgnoreRoute("areas/{area}/content/{*file}");
            context.Routes.IgnoreRoute("modules/{moduleName}/areas/{area}/content/scripts/{*file}");
            context.Routes.IgnoreRoute("modules/{moduleName}/areas/{area}/content/images/{*file}");
            context.Routes.IgnoreRoute("modules/{moduleName}/areas/{area}/content/{*file}");
            ///Modules/MvcEngine.Blog/Areas/StarterSite/Content/Scripts/shBrushCSharp.js"
            context.Routes.IgnoreRoute("captcha.ashx");

            //Ignore editors paths
            context.Routes.IgnoreRoute("Editors/{*file}");
            context.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            context.Routes.IgnoreRoute("Skins/{*pathInfo}");
            context.Routes.IgnoreRoute("Templates/{*pathInfo}");
            context.Routes.IgnoreRoute("Content/{*pathInfo}");

            context.Routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.([iI][cC][oO]|[gG][iI][fF])(/.*)?" });
        }
    }
}
